<?php
	require_once('paths.inc');
	require_once(INCLUDE_PATH.'constants.inc');
	require_once('page.inc');
	require_once(DB_PATH.'db.inc');
	
	require_once('security.inc');
	require_once('utils.inc');	
    require_once('time.inc');
	
	session_start();

	check_permissions(CT_PERM_EDIT_USERS);
	
	html_header("LANG_Add_user_page", null, "add_users");
	select_js_language();	
		
	$db = db_connect();
	try {
		$client = Client::queryLoad($db, $_SESSION['user_logat']->id_client);
	}
	catch (QueryLoadClientException $e) {
		redirectOnError(CT_ADD_USERS_LOAD_CLIENT);
	}
	catch (QueryLoadAddressException $e)  {
		redirectOnError(CT_ADD_USERS_LOAD_ADDRESS);
	}
?>
	<script language="Javascript">
	<!--
	function check_users_number() {
		var nr = document.getElementById("user_number").value;
		if (nr >= <?php echo $client->max_useri; ?>)
			return false;
		else
			return true;
	}
	-->
	</script>
<?php
	try {
		$users = User::queryLoadByClient($db, $_SESSION['user_logat']->id_client, false, $client->admin_user_id);
	}
	catch (QueryLoadUserException $e) {
		redirectOnError(CT_ADD_USERS_LOAD_USER);
	}
	
	$total = count($users);
	$_SESSION['users'] = $users;
    	
	$linkuri = array(LANG_Home => "home.php", LANG_Add_user_page => "");    
	titlu_pagina($linkuri);
	output_notice_msg();
	output_error_msg();
    output_extra_text(LANG_EXTRA_ADD_USERS);

	echo '<div id="users" class="container">';
		render_users_table($users);
	echo "</div>";
	
    echo '<div class="container">';
    	echo '<input type="button" value="' . LANG_Add_user_new . '" onclick="javascript: add_new_user();" />';
	echo "</div>"; 
	html_footer();
?>